import _ from 'lodash';
import { LOCAL, SESSION } from './constants/publicConstant';

export async function getInitialState(): Promise<object> {
  let userInfo: any;
  let menuData: any;
  const tokenVal = sessionStorage.getItem(SESSION.token);
  const userMenuInfo = JSON.parse(localStorage.getItem(LOCAL.USER_PERMISSION) || '{}');

  if (!_.isEmpty(tokenVal)) {
    userInfo = userMenuInfo.userInfo || {};
    menuData = userMenuInfo.allPermissions || [];
  } else {
    userInfo = {};
    menuData = [];
  }

  return { userInfo, menuData };
}
